package examples.computations;

import java.util.ArrayList;

import org.apache.commons.functor.UnaryFunction;


import util.DiffComputation;
import util.Int;
import util.IntList;
import util.functors.AccociBinaryOP;
import util.functors.BinaryOperator;

public class Smaller extends DiffComputation<Int, Int, IntList> {

	public Smaller(Int x) {
		init = x;// new Int(50);
		oplus = new AccociBinaryOP<IntList>() {

			@Override
			public IntList evaluate(IntList left, IntList right) {
				if (left == null || left.get() == null)
					left = new IntList(new ArrayList<Int>());
				if (right != null && right.get() != null
						&& right.get().size() > 0) {
					left.get().addAll(right.get());
				}
				return left;
			}

			@Override
			public IntList id() {
				return new IntList();
			}

		};

		otimes = new AccociBinaryOP<Int>() {
			@Override
			public Int evaluate(Int left, Int right) {

				if (right.get() < left.get())
					return left;
				else
					return right;
			}

			@Override
			public Int id() { // id * x = x
				return new Int(Integer.MIN_VALUE);
			}
		};

		g = new UnaryFunction<Int, IntList>() {
			@Override
			public IntList evaluate(Int obj) {
				return new IntList();
			}

		};

		p = new BinaryOperator<Int, Int, IntList>() {

			@Override
			public IntList evaluate(Int x, Int c) {
				ArrayList<Int> val = new ArrayList<Int>();
				if (x.get() < c.get()) {
					return null;
				} else {
					val.add(x);
					return new IntList(val);
				}
			}

			@Override
			public Int getInstanceOfT0() {
				return new Int(0);
			}

		};

		q = new UnaryFunction<Int, Int>() {
			@Override
			public Int evaluate(Int da) {
				return da;
			}
		};

	}
}
